home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / StdIO / fwrite.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  1KB  |  40 lines

  1. /*
  2.  * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
  3.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  4.  * PDC I/O Library (C) 1987 by J.A. Lydiatt.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this 
  7.  * notice remains intact and that modified versions of this file not
  8.  * be included as part of the PDC Software Distribution without the
  9.  * express consent of the copyright holders.  No warrantee of any
  10.  * kind is provided with this code.  For further information, contact:
  11.  *
  12.  *  PDC Software Distribution    Internet:                     BIX:
  13.  *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
  14.  *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
  15.  */
  16.  
  17. /* fwrite - writes to an output stream */
  18.  
  19. #include <stdio.h>
  20.  
  21. int fwrite(ptr, element_size, count, stream)
  22. char *ptr;
  23. int   element_size;
  24. int   count;
  25. FILE *stream;
  26. {
  27.     int  max_bytes, bytes_left;
  28.  
  29.     max_bytes = bytes_left = count * element_size;
  30.  
  31.     while (bytes_left--) {
  32.         if (putc(*ptr++,stream) == EOF)
  33.             break;
  34.     }
  35.  
  36.     bytes_left++;    /* uh-oh; put it back the way it was! */
  37.  
  38.     return( (element_size != 0) ? ((max_bytes-bytes_left)/element_size) : element_size);
  39. }
  40.